package tetrisgui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.sql.Time;

import tetrismain.Block;
import tetrismain.Board;
import tetrismain.IPiece;
import tetrismain.JPiece;
import tetrismain.LPiece;
import tetrismain.OPiece;
import tetrismain.Piece;
import tetrismain.SPiece;
import tetrismain.TPiece;
import tetrismain.ZPiece;

public class BoardGui extends Component {
	private static int SCALE = 15;
	Board my_board;
	public BoardGui(Board the_piece){
		my_board = the_piece;
	}
	private Color getColor(int color_id){
		Color c;
		switch(color_id){
		case Piece.I_ID:
			c = Color.BLUE;
			break;
		case Piece.J_ID:
			c = Color.GREEN;
			break;
		case Piece.L_ID:
			c = Color.MAGENTA;
			break;
		case Piece.O_ID:
			c = Color.ORANGE;
			break;
		case Piece.S_ID:
			c = Color.RED;
			break;
		case Piece.T_ID:
			c = Color.YELLOW;
			break;
		case Piece.Z_ID:
			c = Color.PINK;
			break;
		default:
			c = Color.GRAY;
			break;		
		}
		return c;
	}
	@Override
	public void paint(Graphics g){
		g.setColor(Color.RED);
		g.drawRect(0, 0, Board.DEFAULT_WIDTH*SCALE+SCALE+1, Board.DEFAULT_HEIGHT*SCALE+SCALE+1);
		for(Block i:my_board.getBlocks()){
			g.setColor(getColor(i.getId()));
			g.drawRect(i.getX()*SCALE, i.getY()*SCALE, SCALE-1, SCALE-1);
		}
		for(Block i:my_board.getCurentPiece().getPiece()){
			g.setColor(getColor(i.getId()));
			g.drawRect(i.getX()*SCALE, i.getY()*SCALE, SCALE-1, SCALE-1);
		}
		if(my_board.gameOver() == true){
			g.drawString("Game Over", 30, 30);
		}
		
	}
}
